{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Fetching_values_of_intermediate_layers.ipynb",
      "provenance": [],
      "include_colab_link": true
    },
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.7.6"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/PacktPublishing/Modern-Computer-Vision-with-PyTorch/blob/master/Chapter02/Fetching_values_of_intermediate_layers.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "ExecuteTime": {
          "end_time": "2020-09-25T19:37:27.437450Z",
          "start_time": "2020-09-25T19:37:27.143217Z"
        },
        "id": "e1gtGb85daHv"
      },
      "source": [
        "import torch\n",
        "x = [[1,2],[3,4],[5,6],[7,8]]\n",
        "y = [[3],[7],[11],[15]]"
      ],
      "execution_count": 1,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "ExecuteTime": {
          "end_time": "2020-09-25T19:37:27.440914Z",
          "start_time": "2020-09-25T19:37:27.438557Z"
        },
        "id": "ZaYGlxtQdbd1"
      },
      "source": [
        "X = torch.tensor(x).float()\n",
        "Y = torch.tensor(y).float()"
      ],
      "execution_count": 2,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "ExecuteTime": {
          "end_time": "2020-09-25T19:37:29.527549Z",
          "start_time": "2020-09-25T19:37:27.442428Z"
        },
        "id": "q5DT95H_dcwi"
      },
      "source": [
        "device = 'cuda' if torch.cuda.is_available() else 'cpu'\n",
        "X = X.to(device)\n",
        "Y = Y.to(device)"
      ],
      "execution_count": 3,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "ExecuteTime": {
          "end_time": "2020-09-25T19:37:29.530750Z",
          "start_time": "2020-09-25T19:37:29.528696Z"
        },
        "id": "rHq7VwgDdeJ-"
      },
      "source": [
        "import torch.nn as nn"
      ],
      "execution_count": 4,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "ExecuteTime": {
          "end_time": "2020-09-25T19:37:29.535567Z",
          "start_time": "2020-09-25T19:37:29.531890Z"
        },
        "id": "clpig_05dfYK"
      },
      "source": [
        "class MyNeuralNet(nn.Module):\n",
        "    def __init__(self):\n",
        "        super().__init__()\n",
        "        self.input_to_hidden_layer = nn.Linear(2,8)\n",
        "        self.hidden_layer_activation = nn.ReLU()\n",
        "        self.hidden_to_output_layer = nn.Linear(8,1)\n",
        "    def forward(self, x):\n",
        "        x = self.input_to_hidden_layer(x)\n",
        "        x = self.hidden_layer_activation(x)\n",
        "        x = self.hidden_to_output_layer(x)\n",
        "        return x"
      ],
      "execution_count": 5,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "ExecuteTime": {
          "end_time": "2020-09-25T19:37:29.540168Z",
          "start_time": "2020-09-25T19:37:29.536723Z"
        },
        "id": "McmLsQstdnxr"
      },
      "source": [
        "torch.random.manual_seed(10)\n",
        "mynet = MyNeuralNet().to(device)"
      ],
      "execution_count": 6,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "ExecuteTime": {
          "end_time": "2020-09-25T19:37:29.544857Z",
          "start_time": "2020-09-25T19:37:29.541272Z"
        },
        "id": "8cyG-B-AdoBB"
      },
      "source": [
        "loss_func = nn.MSELoss()"
      ],
      "execution_count": 7,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "ExecuteTime": {
          "end_time": "2020-09-25T19:37:29.554504Z",
          "start_time": "2020-09-25T19:37:29.546221Z"
        },
        "id": "QRTf8vdKdqmP",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "55370c9b-a407-423b-8baa-aaeeae811b22"
      },
      "source": [
        "_Y = mynet(X)\n",
        "loss_value = loss_func(_Y,Y)\n",
        "print(loss_value)"
      ],
      "execution_count": 8,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "tensor(102.1545, grad_fn=<MseLossBackward>)\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "ExecuteTime": {
          "end_time": "2020-09-25T19:37:29.558932Z",
          "start_time": "2020-09-25T19:37:29.555392Z"
        },
        "id": "dTOdsvFydsQK"
      },
      "source": [
        "from torch.optim import SGD\n",
        "opt = SGD(mynet.parameters(), lr = 0.001)"
      ],
      "execution_count": 9,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "ExecuteTime": {
          "end_time": "2020-09-25T19:37:29.588488Z",
          "start_time": "2020-09-25T19:37:29.560089Z"
        },
        "id": "xyHCZwfYduGO"
      },
      "source": [
        "loss_history = []\n",
        "for _ in range(50):\n",
        "    opt.zero_grad()\n",
        "    loss_value = loss_func(mynet(X),Y)\n",
        "    loss_value.backward()\n",
        "    opt.step()\n",
        "    loss_history.append(loss_value)"
      ],
      "execution_count": 10,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "ExecuteTime": {
          "end_time": "2020-09-25T19:37:29.838987Z",
          "start_time": "2020-09-25T19:37:29.589467Z"
        },
        "id": "DiO6I53udwvY",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 312
        },
        "outputId": "bac08c80-f41e-4d8f-93d1-294e47f3bcb3"
      },
      "source": [
        "import matplotlib.pyplot as plt\n",
        "%matplotlib inline\n",
        "plt.plot(loss_history)\n",
        "plt.title('Loss variation over increasing epochs')\n",
        "plt.xlabel('epochs')\n",
        "plt.ylabel('loss value')"
      ],
      "execution_count": 11,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "Text(0, 0.5, 'loss value')"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 11
        },
        {
          "output_type": "display_data",
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEWCAYAAACJ0YulAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nO3deZxddX3/8dd71myTTJKZDFnJCiQqJBiWAFrLolZR0J8siohKi1aqWLCKVq1arVitSFsqUqFiBQFRCqUomyxFEUiAsiRAQghk38hKwiST+fz+OGeGyzgzuWTm3nPv3PfzkfvI2e49n3Pm3vu+53s2RQRmZmYAVVkXYGZmpcOhYGZmnRwKZmbWyaFgZmadHApmZtbJoWBmZp0cClZQkrZLmrqPzz1D0u39XVOWJF0m6StZ15EPSZPSv1911rX0B0nLJB2fdR2lTj5PoTRJWgb8eUTcmXUtxSBpMvA8UBsRbdlWYwNRpX2m9pW3FKwgJNVkXUPWirUOvK6tPzkUyoykekk/kLQqffxAUn06rknSLZI2S3pJ0v9KqkrHfUHSSknbJD0j6bhuXvsISWtymwskvU/S42n34ZIeSF9/taR/lVSXM21IOlfSYmBxzrDpafe7JT0qaauk5ZK+ljP7+9L/N6dNFvMkfVTS/Tmvf5SkhyVtSf8/KmfcPZL+XtLv0mW8XVJTL+vxLyQtSdfTzZLGpcN/KOl7Xaa9SdL5afc4Sb+UtF7S85I+kzPd1yTdIOlnkrYCH+1mvj+R9M20+22SVki6QNK6dJ1+LGfawZL+SdIL6TLfnw6bnK7XsyW9CPw2nf7jkhZJ2iTpNkn757zWJek63yppgaS35Iw7XNL8dNxaSd9Ph3fMpyafdSzpI2mtGyV9pbfmmvR9/D1JL6bzvEzS4C7r5UuSNqSvc0bOc0dI+mn6N3hB0pc73uc5f9tFaY0LJR2aM+vZkh5P1+d1kgalz+nxs1NxIsKPEnwAy4Djuxn+D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xtW6m29drxORef2cPUJNe9/9wkpvCnAj8Zh9f26xPHApmf+wu4APpNeo77nm7P8nnpeOqmx8C7o+ILcAmSW9Jh58J3Jve8W2FpJPT16iXNKSnGab3fhgREbcCfw0cUogFM9sb32THrIuIWCjpyyR3tKoCdgPnAi8Dh6fj1pHsd4Dk8sSXpV/6S4GPpcPPBH4k6Rvpa5zSy2wbgJskDSLZUjm/nxfLLC++SqpZniRtj4hhWddhVkhuPjIzs07eUjAzs07eUjAzs04OBTMz6+RQMDOzTg4FMzPr5FAwM7NO/x+Udq7XcOXGqgAAAABJRU5ErkJggg==\n",
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ]
          },
          "metadata": {
            "tags": [],
            "needs_background": "light"
          }
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "0-Sn8tA11MKR"
      },
      "source": [
        "### 1. Fetching intermediate values by directly calling the intermediate layer"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "jmfHZmKXdyND",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "7c3a7be9-46c7-461e-8e37-19e28ac07ff1"
      },
      "source": [
        "mynet.input_to_hidden_layer(X)"
      ],
      "execution_count": 12,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "tensor([[-4.0139e-01,  7.2155e-03, -4.9131e-01,  1.4615e+00, -3.8093e-01,\n",
              "         -7.1646e-01,  4.6765e-01,  2.0814e+00],\n",
              "        [-5.6844e-01, -2.2575e-01, -1.5498e+00,  3.1695e+00, -5.2755e-01,\n",
              "         -7.3935e-01,  1.9716e+00,  5.3073e+00],\n",
              "        [-7.3548e-01, -4.5871e-01, -2.6083e+00,  4.8776e+00, -6.7418e-01,\n",
              "         -7.6225e-01,  3.4756e+00,  8.5332e+00],\n",
              "        [-9.0252e-01, -6.9167e-01, -3.6667e+00,  6.5856e+00, -8.2080e-01,\n",
              "         -7.8514e-01,  4.9795e+00,  1.1759e+01]], grad_fn=<AddmmBackward>)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 12
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "bPkK_o_r2J0y"
      },
      "source": [
        "### 2. Fetching intermediate values by returning them in `nn.Module` definition"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 312
        },
        "id": "yarZlkt71Qrw",
        "outputId": "e4129b1f-2291-417a-b025-d47d73e23beb"
      },
      "source": [
        "torch.random.manual_seed(10)\n",
        "class MyNeuralNet(nn.Module):\n",
        "    def __init__(self):\n",
        "        super().__init__()\n",
        "        self.input_to_hidden_layer = nn.Linear(2,8)\n",
        "        self.hidden_layer_activation = nn.ReLU()\n",
        "        self.hidden_to_output_layer = nn.Linear(8,1)\n",
        "    def forward(self, x):\n",
        "        hidden1 = self.input_to_hidden_layer(x)\n",
        "        hidden2 = self.hidden_layer_activation(hidden1)\n",
        "        x = self.hidden_to_output_layer(hidden2)\n",
        "        return x, hidden1\n",
        "\n",
        "mynet = MyNeuralNet().to(device)\n",
        "loss_func = nn.MSELoss()\n",
        "_Y, _Y_hidden = mynet(X)\n",
        "loss_value = loss_func(_Y,Y)\n",
        "opt = SGD(mynet.parameters(), lr = 0.001)\n",
        "loss_history = []\n",
        "for _ in range(50):\n",
        "    opt.zero_grad()\n",
        "    loss_value = loss_func(mynet(X)[0],Y)\n",
        "    loss_value.backward()\n",
        "    opt.step()\n",
        "    loss_history.append(loss_value)\n",
        "\n",
        "import matplotlib.pyplot as plt\n",
        "%matplotlib inline\n",
        "plt.plot(loss_history)\n",
        "plt.title('Loss variation over increasing epochs')\n",
        "plt.xlabel('epochs')\n",
        "plt.ylabel('loss value')"
      ],
      "execution_count": 13,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "Text(0, 0.5, 'loss value')"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 13
        },
        {
          "output_type": "display_data",
          "data":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77nm7P8nnpeOqmx8C7o+ILcAmSW9Jh58J3Jve8W2FpJPT16iXNKSnGab3fhgREbcCfw0cUogFM9sb32THrIuIWCjpyyR3tKoCdgPnAi8Dh6fj1pHsd4Dk8sSXpV/6S4GPpcPPBH4k6Rvpa5zSy2wbgJskDSLZUjm/nxfLLC++SqpZniRtj4hhWddhVkhuPjIzs07eUjAzs07eUjAzs04OBTMz6+RQMDOzTg4FMzPr5FAwM7NO/x+Udq7XcOXGqgAAAABJRU5ErkJggg==\n",
            "text/plain": [
              "<Figure size 432x288 with 1 Axes>"
            ]
          },
          "metadata": {
            "tags": [],
            "needs_background": "light"
          }
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "sNQxAxOM1oaX",
        "outputId": "f2219f64-dd84-4ba7-f2fd-f36a96e348c1"
      },
      "source": [
        "mynet(X)[1]"
      ],
      "execution_count": 14,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "tensor([[-4.0139e-01,  7.2155e-03, -4.9131e-01,  1.4615e+00, -3.8093e-01,\n",
              "         -7.1646e-01,  4.6765e-01,  2.0814e+00],\n",
              "        [-5.6844e-01, -2.2575e-01, -1.5498e+00,  3.1695e+00, -5.2755e-01,\n",
              "         -7.3935e-01,  1.9716e+00,  5.3073e+00],\n",
              "        [-7.3548e-01, -4.5871e-01, -2.6083e+00,  4.8776e+00, -6.7418e-01,\n",
              "         -7.6225e-01,  3.4756e+00,  8.5332e+00],\n",
              "        [-9.0252e-01, -6.9167e-01, -3.6667e+00,  6.5856e+00, -8.2080e-01,\n",
              "         -7.8514e-01,  4.9795e+00,  1.1759e+01]], grad_fn=<AddmmBackward>)"
            ]
          },
          "metadata": {
            "tags": []
          },
          "execution_count": 14
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "vXZvZI-U1pcK"
      },
      "source": [
        ""
      ],
      "execution_count": 14,
      "outputs": []
    }
  ]
}